package com.yangrong.thread.timer;

import java.util.Timer;
import java.util.TimerTask;

public class TraditionalTimerTest {

	private static boolean flag = true;

	public static void main(String[] args) {
		int s = 0;

		class MyTimerTask extends TimerTask {
			@Override
			public void run() {
				flag = !flag;
				System.out.println("Bombing!");
				new Timer().schedule(new MyTimerTask(), (flag ? 2000 : 4000));
			}

		}

		new Timer().schedule(new MyTimerTask(), 2000);

		while (true) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(s += 1);
		}
	}

}
